package ar.edu.itba.it.poo.dd.backend

import scala.Math._

sealed abstract class EnemyType(val name: String)
case object Dragon extends EnemyType("Dragon")
case object Golem extends EnemyType("Golem")
case object Snake extends EnemyType("Snake")

class Enemy(val enemyType: EnemyType, val level: Int, val maxHealth: Int, val maxStrength: Int) extends Fighter(maxHealth, maxStrength) with Tile {
  val name = enemyType.name
  def canEnter(player: Player) = {
    if (isAlive) {
      player.fight(this)
      if (!isAlive && player.isAlive) player.accumExperience(level)
      false
    } else {
      true
    }
  }

  def onPlayerEnter(player: Player) {}
}

object Enemy {
  def createDragon(level: Int) = new Enemy(Dragon, level, health(level, 1.35), strength(level, 1))
  def createGolem(level: Int) = new Enemy(Golem, level, health(level, 1), strength(level, 0.7))
  def createSnake(level: Int) = new Enemy(Snake, level, health(level, 1), strength(level, 1))

  private def health(level: Int, h: Double) = floor((pow((level + 3), 2) - 10) * h).toInt
  private def strength(level: Int, s: Double) = floor((pow(level, 2) + 5 * level) * 0.5 * s).toInt
}